import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../tools/const.dart';

class CommonButton extends StatelessWidget {
  ///按钮显示文案,默认'确认'
  final String? title;

  ///是否可用,false 是置灰效果
  final bool isEnable;

  ///点击回调
  final VoidCallback? onTap;

  ///默认父布局可用空间
  final double? width;

  ///默认父布局可用空间
  final double? height;

  ///字体大小
  final double? fontSize;

  ///背景色
  final Color? bgColor;
  ///字体颜色
  final Color? textColor;
  ///圆角
  final double? borderRadius;

  const CommonButton({
    Key? key,
    this.title = '确认',
    this.width,
    this.height,
    this.isEnable = true,
    this.onTap,
    this.bgColor,
    this.textColor,
    this.fontSize = 16,
    this.borderRadius,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: BoxConstraints.tightFor(
          width: width ?? double.infinity,
          height: height ?? 46,),
      child: ElevatedButton(
          style:ButtonStyle(
            side:  isEnable ?  MaterialStateProperty.all(
              BorderSide(
                color: globalColor(),
                width: 1.5,
              ),
            ) : null,
            elevation: MaterialStateProperty.all(0),
            backgroundColor:
                isEnable ? MaterialStateProperty.all(bgColor ?? globalColor()) : MaterialStateProperty.all(Color(0xffC3C3C3)),
            // foregroundColor: MaterialStateProperty.all(Colors.white),
            // elevation: isEnable ? MaterialStateProperty.all(10) : MaterialStateProperty.all(0),
            shape: MaterialStateProperty.all(RoundedRectangleBorder(
                borderRadius: borderRadius == null ? BorderRadius.circular((height ?? 50)/2) : BorderRadius.circular(borderRadius!))),
          ),
          onPressed: isEnable ? onTap: null,
          child: Text(
            title!,
            style: TextStyle(fontSize: fontSize!.sp,color: textColor ?? Colors.white,),
          )),
    );
  }
}
